<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
  </style>
</head>

<body>
  <!-- 
  webworker教程:  http://www.ruanyifeng.com/blog/2018/07/web-worker.html
  https://juejin.cn/post/6896104084899069966
  主进程
    let worker = new Worker('work.js');
      worker.postMessage("你好work.js");
        给线程发送消息
      worker.addEventListener("message", (e) => {
        监听线程的消息
        console.log(e.data);
      });
      importScripts('script1.js', 'script2.js');
        可同时加载多个脚本
      worker.addEventListener('error', (e) => {
        监听错误信息
        console.err(e);
      });
    worker.terminate();
      关闭worker主进程
      
    注意:
      webworker不能操作Dom


  子进程
    self是子进程的本身
    self.addEventListener("message", (e) => {
      console.log(e.data);
      self.postMessage(`您好！index.html...`);
    });
    self.close();
      关闭线程
    
-->
  <script>
    let worker = new Worker('1work.js');
    worker.postMessage("你好work.js");
    worker.addEventListener("message", (e) => {
      console.log(e.data);
    });
    setTimeout(() => {
      console.log(`好事多磨`);
    }, 0);
  </script>
</body>

</html>